package com.hhkj.api.common.controller;

import cn.hutool.core.util.ObjectUtil;
import com.hhkj.admin.conf.common.cont.ConfConst;
import com.hhkj.admin.conf.service.biz.ConfBizService;
import com.hhkj.api.sale.common.session.model.LoginSale;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.exception.GlobalException;
import com.ruoyi.framework.login.api.ApiLogin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * ApiConfController
 *
 * @author HHKJ-SERVER-ZJ
 * @since 2023/11/3 9:38
 */
@RequestMapping("/api/conf")
@RestController
public class ApiConfController extends BaseController {

    @Autowired
    private ConfBizService confBizService;

    /** 获取配置信息 */
    @ApiLogin(LoginSale.class)
    @GetMapping("/{code}")
    public AjaxResult getConfByCode(@PathVariable("code") String code) {

        ConfConst.Code confCodeEnum = ConfConst.Code.getByCode(code);
        if (ObjectUtil.isNull(confCodeEnum)) {
            throw new GlobalException("参数错误");
        }
        return AjaxResult.successData(confBizService.getConf(confCodeEnum));
    }
}
